/**
 * @author ChaP
 * @date 2019/07/19
 * @describe:
 */
package CodingTest.AC20190719;

import java.util.ArrayList;
import java.util.Stack;

/**
 * leetcode - 530
 * 二叉搜索树的最小绝对差
 */
public class getMinimumDifference {
    public class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x){val = x;}
    }
    TreeNode pre = null;
    int min = Integer.MAX_VALUE;
   public int getMinimumDifference(TreeNode root){
      inOrder(root);
      return min;
   }
   public void inOrder(TreeNode root){
       if(root == null) return ;
       inOrder(root.left);
       if(pre!=null){
           int dif = Math.abs(root.val - pre.val);
           if(dif < min) min = dif;
       }
       pre = root;
       inOrder(root.right);
   }





}

